import Sprite from '../js/base/sprite.js'

const CANVAS_WIDTH = canvas.width
const CANVAS_HEIGHT = canvas.height

const ROUND_IMG_SRC = 'images/round.png'
const ROUND_WIDTH = 20
const ROUND_HEIGHT = 20

// 圆球的移动速度
let speed =  3

const __ = {
  speed: Symbol('speed')
}

export default class Round extends Sprite{
  constructor(){
    super(ROUND_IMG_SRC, ROUND_WIDTH, ROUND_HEIGHT)
    this.init(CANVAS_WIDTH / 2 - ROUND_WIDTH/2, CANVAS_HEIGHT - 60, speed)
    this.xFlag = speed
    this.yFlag = -speed
    this.width = ROUND_WIDTH
    this.speed = speed
  }

  init(x, y, speed) {
    this.x = x
    this.y = y

    this[__.speed] = speed

    this.visible = true
  }

  // 每一帧更新圆球的位置
  update(xFlag, yFlag) {
    this.xFlag = xFlag
    this.yFlag = yFlag
    
    if (xFlag == -speed) {
      this.x -= this[__.speed]
    } else {
      this.x += this[__.speed]
    }

    if (yFlag == -speed){
      this.y -= this[__.speed]
    }else{
      this.y += this[__.speed]
    }
    
  }
}